package com.github.tetrisgame.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;

import com.github.tetrisgame.utils.Constants;

public class CircleProgressBar extends View {
    private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private final int outsideCircleSize = Constants.OUTSIDECIRCLESIZE;
    private final int insideCircleSize = Constants.INSIDECIRCLESIZE;
    private int time = 0;
    private int totalTime = 360;
    private int sweepAngle;

    public CircleProgressBar(Context context) {
        super(context);
    }

    public CircleProgressBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public void setTotalTime(int totalTime){
        this.totalTime = totalTime;
        sweepAngle = 360 / totalTime;
    }
    public void setTime(int time){
        this.time = time;
    }

    @Override
    protected synchronized void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        mPaint.setColor(Color.parseColor("#AAAAAA"));

        canvas.drawCircle(outsideCircleSize,outsideCircleSize,outsideCircleSize,mPaint);
        mPaint.setColor(Color.parseColor("#4CAF50"));
        canvas.drawArc(
                0, 0,  // 左、上
                2 * outsideCircleSize, 2 * outsideCircleSize,  // 右、下
                -90f,  time*1f,              // 起始角度、扫过角度
                true,                                // 是否包含圆心（false为圆弧）
                mPaint
        );

        mPaint.setColor(Color.parseColor("#FFFFFF"));
        canvas.drawCircle(outsideCircleSize,outsideCircleSize,insideCircleSize,mPaint);
        mPaint.setColor(Color.parseColor("#000000"));
        mPaint.setTextSize(30f);
        canvas.drawText("跳过",outsideCircleSize-30f,outsideCircleSize+10f,mPaint);

    }


}
